﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.DataAccess;
using University.Workshop.Model;
using System.Collections;
using System.Collections.ObjectModel;

namespace University.Workshop.Business
{
    public static class ShoppingCartManager
    {
        static Collection<Product> list = new Collection<Product>();
        public static Collection<Product> AddToTheCart(long productId,short quantity)
        {
            Product product = DataAccess.ProductDataAccess.GetProductById(productId);
            product.Quantity = quantity;
            list.Add(product);
            return list;
        }
        public static float ShowTotalPrice()
        {
            float price = 0;
            foreach (Product p in list)
            {
                price += (p.Price*p.Quantity);
            }
            return price;
        }
        public static Collection<Product> ShowList(Collection<Product> list)
        {
            return list;
        }
        public static Collection<Product> RemoveAProduct(long productId,Collection<Product> list)
        {
            try
            {
                if (list != null)
                {
                    Product toRemove = null;
                    foreach (var item in list)
                    {
                        if (item.ProductId == productId)
                        {
                            toRemove = item;
                            break;
                        }
                    }
                    list.Remove(toRemove);
                }
            }
            catch (Exception)
            {
                throw new BusinessException("Something is wrong");
            }
            return list;
        }
    }
   
}
